<%--
  Created by IntelliJ IDEA.
  User: hanni
  Date: 2019/1/20 0020
  Time: 14:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="./static/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="./static/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="./static/easyui/themes/color.css">
    <script type="text/javascript" src="./static/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="./static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./static/easyui/locale/easyui-lang-zh_CN.js"></script>

</head>


<body>
<div>
    <table id="dg"></table>
    <div id="toolbar">
        <a href="javascript:add()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">增加</a>
        <span style="margin-left: 100px">司机姓名：</span>
        <input class="easyui-textbox" name="jname" id="searchName">
        <a href="javascript:search()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
    </div>
    <div id="dig" class="easyui-dialog"
             style="width: 100%;max-width:800px;padding: 30px 60px;"
             title="添加和编辑的弹框"
             data-options="closed:true,modal:true,closable:true,resizable:true"
                >
            <form id="fm" method="post" class="easyui-form" enctype="multipart/form-data">
                <input name="jid" type="hidden">

                <div style="margin-bottom: 20px">
                    <input class="easyui-textbox" name="jnum" style="width:100%" data-options="label:'驾驶证号码',required:true" />
                </div>
                <div style="margin-bottom: 20px">
                    <input class="easyui-textbox" name="jname" style="width:100%" data-options="label:'司机姓名',required:true" />
                </div>
                <div style="margin-bottom: 20px">
                    <input class="easyui-textbox" name="jsex" style="width:100%" data-options="label:'性别',required:true" />
                </div>
                <div style="margin-bottom: 20px">
                    <span style="margin-right: 50px">地区</span>
                    <input class="easyui-combobox" name="sheng" id="s1">
                    <input class="easyui-combobox" name="shi" id="s2">
                    <input class="easyui-combobox" name="qu" id="s3">
                </div>
                <div style="margin-bottom: 20px">
                    <input class="easyui-datebox" name="fdate" style="width:100%" data-options="label:'发证日期',required:true" />
                </div>


                <div style="text-align: center;padding: 5px 0">
                    <a href="javascript:submitForm()" class="easyui-linkbutton">保存</a>
                    <a href="javascript:cancelFrom()" class="easyui-linkbutton">取消</a>
                </div>


            </form>


        </div>
</div>


<script type="text/javascript">
    $(function () {

        //数据展示
        $('#dg').datagrid({
            url:'/list',
            columns:[[
                {field:'jnum',title:'驾驶证号码'},
                {field:'jname',title:'司机姓名'},
                {field:'jsex',title:'性别'},
                {field:'sheng',title:'省'},
                {field:'shi',title:'市'},
                {field:'qu',title:'区'},
                {field:'fdate',title:'发证日期'},
                {field:'jtiao',title:'违章条数',formatter:function (val,row,index) {

                    return '<a href="javascript:weizhang()" >'+row.jtiao+'</a>'

                    }},
                {field:'op',title:'操作',width:100,formatter:function (val,row,index) {

                    return '<a href="javascript:update()" class="easyui-linkbutton" data-options="iconCls:\'icon-edit\'">修改</a>'
                    }},
            ]],
            pagination:true,
            pageSize:3,
            pageList:[3,6,9],
            toolbar:'#toolbar',
            onLoadSuccess:function () {
                $.parser.parse();
            }

        })


        //三级联动
        $("#s1").combobox({
            url:'/listCheng?pid=0',
            valueField:'cname',
            textField:'cname',
            panelHeight: 'auto',
            onSelect:function (val) {
                $('#s2').combobox('clear')
                $('#s3').combobox('clear')
                getS2(val.cid);
            }

        })



    })

    function getS2(pid) {
        $("#s2").combobox({
            url:'/listCheng?pid='+pid,
            valueField:'cname',
            textField:'cname',
            panelHeight: 'auto',
            onSelect:function (val) {
                $('#s3').combobox('clear')
                getS3(val.cid);
            }

        })

    }

    function getS3(pid) {
        $("#s3").combobox({
            url:'/listCheng?pid='+pid,
            valueField:'cname',
            textField:'cname',
            panelHeight: 'auto'

        })
    }

    //添加操作
    function add() {
        $('#fm').form('clear')
        $('#dig').dialog('open')
    }

    function submitForm() {

        $('#fm').form('submit',{
            url:'/add',
            onSubmit:function (param) {
                // param.sheng=$('#sheng').text()
                // param.shi=$('#shi').text()
                // param.qu=$('#qu').text()


                return $(this).form('validate')
            },
            success:function (data) {

                var data = $.parseJSON(data)
                if(data.success){

                    $('#dig').dialog('close')
                    $('#dg').datagrid('reload')
                }
            }
        })

    }
    function cancelFrom() {
        $('#dig').dialog('close')
    }

    //添加结束

    //修改开始
    function update() {

        var rows = $('#dg').datagrid('getSelections')


        if(rows.length!=0){

            var row = rows[0];
            $('#fm').form('load',row)
            $('#dig').dialog('open')
        }else{

            $.messager.alert('提示','请选择一条数据','info')
        }
    }

    //修改结束

    //查找
    function search() {

        var jnameVal = $('#searchName').val()


        $('#dg').datagrid('load',{
            jname:jnameVal,
        })

    }

    //查找结束

    //违章显示
    function weizhang() {

        var rows = $('#dg').datagrid('getSelections')
        if(rows!=0){
            var row = rows[0];
           // location = "/weizhang?jid="+row.jid;
            location = "weizhang.jsp?jid="+row.jid;

        }else{

            $.messager.alert('提示','请选择一条数据','info')
        }


    }



</script>

</body>
</html>
